<template>
  <div id="div">
    <div id="zhuce" style="box-shadow: 2px 2px 5px ">
      <h3>重置密码</h3>
      <el-input v-model="user.phone" placeholder="手机号" style="width: 400px" class="input"></el-input>
      <el-input v-model="user.cde" placeholder="验证码" style="width: 230px;"class="input"></el-input>
      <el-button type="primary" style="width: 120px;height: 35px;margin-left: 50px" @click="toCode()" >发送验证码</el-button>
      <el-input v-model="user.endPassword" placeholder="至少6位密码，区分大小写" style="width: 400px;" class="input" show-password></el-input>
      <el-input v-model="user.password" placeholder="确认密码" style="width: 400px;"class="input" show-password></el-input>
      <el-button type="primary" style="width: 400px;margin-top: 20px;margin-bottom: 30px" @click="toUpdatPws()">确认重置</el-button>
      <br>
      <el-link type="primary" @click="$router.back()">记起密码，直接登录</el-link>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      user:{}
    }
  },
  methods:{
    toCode(){
      if (this.user.phone!=null && this.user.phone.length==11 && this.user.phone!=''){
        this.axios.post(`user/user/loginCode?phone=${this.user.phone}`).then(res=>{
          if (res.data.code==200){
            this.$message.success("发送成功")
          }else {
            this.$message.error(res.data.msg)
          }
        })
      }else {
        this.$message.error("请输入正确的手机号")
      }
    },
    toUpdatPws(){
      if (this.user.phone!=null && this.user.phone.length==11 && this.user.phone!=''){
        if (this.user.cde!=null && this.user.cde.length==4 && this.user.cde!=''){
          if (this.user.endPassword!=null && this.user.endPassword.length>=6 && this.user.endPassword!=''){
            if (this.user.endPassword==this.user.password){
              this.axios.post(`user/user/password`,this.user).then(res=>{
                if (res.data.code=200){
                  this.$message.success("重置成功")
                  this.$router.back();
                }else {
                  this.$message.error(res.data.msg)
                }
              })
            }else {
              this.$message.error("两次密码必须输入一致")
            }
          }else {
            this.$message.error("请输入正确的密码")
          }
        }else {
          this.$message.error("请输入正确的验证码")
        }
      }else {
        this.$message.error("请输入正确的手机号")
      }
    }
  },
  created() {
// 获取数据
//     const data = JSON.parse(localStorage.getItem('user'));
//     //赋值然后显示登陆人
//     this.user = data
  }
}
</script>

<style>
#div{
  width: 950px;
  height: 600px;
  padding-top: 100px;
  padding-left: 500px;
}
#zhuce{
  box-sizing: border-box;
  padding-top: 50px;
  width: 550px;
  height: 550px;
}
</style>
